<?php
namespace app\admin\controller;
use app\model\DiscountRecord as DiscountRecordModel;
use think\Db;


class DiscountRecord extends Base
{
    public function __construct(){
        $model = new DiscountRecordModel();
        $this->model = $model;
        parent::__construct();
        
        $page_info = $this->page_info;
        $page_info['title'] = '折扣记录';


        $this->assign([
            'model'=>$this->model,
            'page_info'=>$page_info
        ]);
    }

    public function index(){
        $model = $this->model;
        $map_params = [
            ['key'=>'user_id','type'=>'='],
        ];
        $map = getSearchParam($map_params);

        $page_param = [
            'page'=>input('page',1),
            'list_rows'=>input('page_size',20)
        ];
        $list = $model->where($map)->order('id','desc')->paginate($page_param);
        $page = $list->render();

        $list = $list->toarray();
        foreach ($list['data'] as $k => $vo) {
            $list['data'][$k]['admin_truename'] = Db::name('admin')->where('id',$vo['admin_id'])->value('truename');
            $list['data'][$k]['user_name'] = Db::name('user')->where('id',$vo['user_id'])->value('name');
        }
        return view('index', [
            'list'=>$list,
            'page'=>$page
        ]);
    }


}
